def maj_ele(nums):
    c1 = None
    c1_cnt = 0
    c2 = None
    c2_cnt = 0

    for num in nums:
        if num == c1:
            c1_cnt += 1
        elif num == c2:
            c2_cnt += 1
        elif not c1_cnt:
            c1 = num
            c1_cnt = 1
        elif not c2_cnt:
            c2 = num
            c2_cnt = 1
        else:
            c1_cnt -= 1
            c2_cnt -= 1

    result = set()
    if nums.count(c1) > len(nums)/3:
        result.add(c1)
    if nums.count(c2) > len(nums)/3:
        result.add(c2)

    return list(result)

print(maj_ele([1,1,1,3,3,2,2,2]))